package com.xp.record25.bio;

import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class NewBioServer {

    public static void main(String[] args) throws IOException {
        ServerSocketChannel ssc = ServerSocketChannel.open();
        ssc.bind(new InetSocketAddress(8888));
        ByteBuffer buffer = ByteBuffer.allocate(16);
        while (true){
            System.out.println("等待链接。。。。。");
            SocketChannel sc = ssc.accept();
            System.out.println("链接成功。。。。。"+sc);
            System.out.println("准备接收数据。。。。。");
            sc.read(buffer);
            buffer.flip();
            System.out.println("接收到数据。。。。。"+new String(buffer.array()));
            buffer.clear();
        }
    }
}
